﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace FWMS
{
    public partial class Form_churukuchoose : Form
    {
        public Form_churukuchoose()
        {
            InitializeComponent();
        }
        private enum choosestyle : int
        {
            原材料选择 = 0,
            调味料选择 =1,
            辅料选择 = 2,
            产品选择 = 3
        }
        private void Form_churukuchoose_Load(object sender, EventArgs e)
        {
            choosestyle style = new choosestyle();
            style = (choosestyle)COMMAND.CommandBean.cailiaostyle;
            this.label_allinfo.Text = style.ToString();

            //材料选择初使化
            COMMAND.CommandBean.formflag = false;
            Bean.RukucailiaoChooseBean bean = new FWMS.Bean.RukucailiaoChooseBean();
            Service.RukucailiaoChooseService rukucailiaoservice = new FWMS.Service.RukucailiaoChooseService();

            bean.Rukustyle = (int)style;
            bean = rukucailiaoservice.rukucailiaochooseServiceSelectContation(bean);
            if (bean.Selectresult == null)
            {
                MessageBox.Show("数据库中无材料");
            }
            else
            {
                for (int i = 0; i < bean.Resultrow; i++)
                {
                    this.listBox_all.Items.Add(bean.Selectresult[i,1]);
                }
            }


        }
        //选择
        private void button_select_Click(object sender, EventArgs e)
        {
            int a = this.listBox_all.SelectedIndex;
            if (a < 0)
            {
                return;
            }
            else
            {
                for (int j = this.listBox_selected.Items.Count - 1; j >= 0; j--)
                {
                    if (this.listBox_all.Items[a].ToString().Trim().Equals(this.listBox_selected.Items[j].ToString().Trim()))
                    {
                        return;
                    }
                }
                this.listBox_selected.Items.Add(this.listBox_all.Items[a]);
            }
        }
        //清除
        private void button_delete_Click(object sender, EventArgs e)
        {
            for (int i = this.listBox_selected.Items.Count - 1; i >= 0; i--)
            {
                this.listBox_selected.Items.Remove(this.listBox_selected.SelectedItem);
            }
        }

        private void listBox_all_DoubleClick(object sender, EventArgs e)
        {
            button_select_Click(sender, e);
        }

        private void listBox_selected_DoubleClick(object sender, EventArgs e)
        {
            button_delete_Click(sender, e);
        }

        private void bt_ok_Click(object sender, EventArgs e)
        {
             object[,] selectresult = new object[this.listBox_selected.Items.Count,2];
             for (int i = 0; i < this.listBox_selected.Items.Count; i++)
             {
                 selectresult[i, 0] = i;
                 selectresult[i, 1] = this.listBox_selected.Items[i].ToString(); 
             }
             COMMAND.CommandBean.rukuyuancailiaoresult = selectresult;
             COMMAND.CommandBean.rows = this.listBox_selected.Items.Count;
             this.Close();
        }
    }
}
